﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace Medianamik.Core
{
    public abstract class MedianamikDTO : IMedianamikDTO, IEquatable<MedianamikDTO>
    {
        protected MedianamikDTO(Guid? nodeId, Guid? parentId, Guid typeId, CultureInfo culture, short? position)
        {
            NodeId = nodeId.GetValueOrDefault(Guid.NewGuid());
            ParentNodeId = parentId;
            TypeId = typeId;
            Culture = culture;
            Position = position;
        }

        public Guid NodeId { get; private set; }

        public Guid? ParentNodeId { get; private set; }

        public Guid TypeId { get; private set; }

        public CultureInfo Culture { get; private set; }
        public short? Position { get; private set; }

        public bool Equals(MedianamikDTO other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.NodeId.Equals(NodeId) && Equals(other.Culture, Culture);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(MedianamikDTO)) return false;
            return Equals((MedianamikDTO)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (NodeId.GetHashCode() * 397) ^ Culture.GetHashCode();
            }
        }

        public static bool operator ==(MedianamikDTO left, MedianamikDTO right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(MedianamikDTO left, MedianamikDTO right)
        {
            return !Equals(left, right);
        }
    }
}
